<?php
include_once("../../modules/checkA.php");
include_once("../../../config.php");
$plate=select_one_line_all_items($table_Prefix."plate","mid = 'finance'");
?>


<?
//用来判断当前系统属于什么板块
$system_part = $plate['mid'];

if(!$_REQUEST ['applydate'])
{
    $_REQUEST ['applydate']=date("Y-m");
}
$applydate  = addslashes($_REQUEST ['applydate']);


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
       <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <?php include 'modules/head.php'; ?>
    <?php include_once("../controller/payment.php"); ?>



    <style>
        body>.detail-staitics-info .agent-list li{font-size: 12px!important; width:100px;}
        body>.detail-staitics-info .layui-table td, .layui-table th{font-size: 12px!important;}
    </style>








</head>

<body>

<div id="topbar">   <?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?></div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>




        <div id="content">
            <h1>工资表</h1>

            <div class="select-box layui-form">
                <form action="payment.php?nav-itemed=finance" >

                    <input type="hidden" name ="nid"         value="<? echo $_REQUEST['nid']?>"/>
                    <input type="hidden" name ="nav-itemed"  value="finance"/>

                    <div class="layui-form-item">
                        <label class="layui-form-label">时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="select_tb_ontime" placeholder="请输入时间节点" autocomplete="off" class="layui-input"
                                   onclick="laydate({istime: true, format: 'YYYY-MM'})" style="float: left; width: 112px"
                                   value="<?if($_REQUEST['select_tb_ontime']){echo $_REQUEST['select_tb_ontime'] ;} ?>" >
                        </div>
                    </div>


                    <button class="layui-btn" ><i class="layui-icon">&#xe615;</i> 查找</button>
                    <br class="clearfloat"/>
                </form>

                <br class="clearfloat"/>
            </div>



            <!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
            <div class="list-box">



    <table class="layui-table">

        <thead>
        <tr>
            <th>员工</th>
            <th>基本工资</th>
            <th>Tb绩效</th>
<!--            <th>Tb详情</th>-->
            <th>考勤</th>
            <th>提成</th>
            <th>合计</th>
        </tr>
        </thead>


        <tbody>
        <?foreach ($employee_list as $k=>$v){?>
            <tr>
                <td><?echo $v['name']?></td>
                <td><?echo $v['salary']?></td>
                <td><?
                    $parameter['key']="executor";//需要统计的键值
                    $parameter['value']=$v['designation'];//需要统计

                    echo $kpi=-0.5*count_sum_with_key_in_2d_array($tbkpi,$parameter)?></td>
<!--                <td>-->
<!--                    --><?//foreach ($tbkpi as $k2=>$v2)
//                    {
//                        if($v2['executor']==$v['designation'])
//                        {?>
<!--                            <div>--><?//echo  $v2['project']."  |  ".$v2['name']." 【".$v2['enddays']."   |  ".substr($v2['date'],0,10)."】"?><!--</div>-->
<!--                        --><?//;}
//                        ?>
<!--                    --><?//}?>
<!--                    </td>-->
                <td>未接入自动统计</td>



                <?


                $sum_agent2=array();
                $sum_sales2=array();
                $sum_respon2=array();
                $sum_service2=array();
                $sum_designer2=array();
                $sum_programer2=array();
                $sum_editor2=array();


                $workerid=$v['nid'];


                //经过复杂的计算，计算出上一个月的提成
                $last_month=$_REQUEST['select_tb_ontime'];

                $case_list2 = select_lines_all_items($table_Prefix . "case", "nid desc", "
                                (agent     ='" . $workerid . "' or
                                respon    ='" . $workerid . "' or
                                sales     ='" . $workerid . "' or
                                service   ='" . $workerid . "' or
                                designer  ='" . $workerid . "' or
                                programer ='" . $workerid . "' or
                                editor    ='" . $workerid . "') and startdate > '2018-12-31 23:59:59' and paydate like '".$last_month."%' ", "");


                $case_id_list2=transform_2darray_in_1darray_number_as_key($case_list2,"nid");

                $case_id_list_srt2=implode(",", $case_id_list2);

                $bonus_list2 = select_lines_all_items($table_Prefix . "bonus_record", "nid desc", "caseid in (".$case_id_list_srt2.")", "0");

                foreach($bonus_list2 as $kb => $vb)
                {
                    $case_bonus2[$vb['caseid']]=$vb;
                }


                for($i=0;$i<count($case_list2);$i++)
                {

                    if($case_bonus2[$case_list2[$i]['nid']]['agent']==$workerid){  $case_bonus2[$case_list2[$i]['nid']]['agent_bonus'];
                        $sum_agent2[]=$case_bonus2[$case_list2[$i]['nid']]['agent_bonus'];}

                    if($case_bonus2[$case_list2[$i]['nid']]['sales']==$workerid){  $case_bonus2[$case_list2[$i]['nid']]['sales_bonus'];
                        $sum_sales2[]=$case_bonus2[$case_list2[$i]['nid']]['sales_bonus'];}

                    if($case_bonus2[$case_list2[$i]['nid']]['respon']==$workerid){  $case_bonus2[$case_list2[$i]['nid']]['respon_bonus'];
                        $sum_respon2[]=$case_bonus2[$case_list2[$i]['nid']]['respon_bonus'];}

                    if($case_bonus2[$case_list2[$i]['nid']]['service']==$workerid){  $case_bonus2[$case_list2[$i]['nid']]['service_bonus'];
                        $sum_service2[]=$case_bonus2[$case_list2[$i]['nid']]['service_bonus'];}

                    if($case_bonus2[$case_list2[$i]['nid']]['designer']==$workerid){  $case_bonus2[$case_list2[$i]['nid']]['designer_bonus'];
                        $sum_designer2[]=$case_bonus2[$case_list2[$i]['nid']]['designer_bonus'];}

                    if($case_bonus2[$case_list2[$i]['nid']]['programer']==$workerid){  $case_bonus2[$case_list2[$i]['nid']]['programer_bonus'];
                        $sum_programer2[]=$case_bonus2[$case_list2[$i]['nid']]['programer_bonus'];}

                    if($case_bonus2[$case_list2[$i]['nid']]['editor']==$workerid){  $case_bonus2[$case_list2[$i]['nid']]['editor_bonus'];
                        $sum_editor2[]=$case_bonus2[$case_list2[$i]['nid']]['editor_bonus'];}
                }


                $bonus=array_sum($sum_agent2)+array_sum($sum_sales2)+
                       array_sum($sum_respon2)+array_sum($sum_service2)+
                       array_sum($sum_designer2)+array_sum($sum_programer2)+
                       array_sum($sum_editor2);


                ?>
                <td><?echo $bonus?></td>
                <td><?echo $v['salary']+$kpi+$bonus?></td>
            </tr>
        <?;}?>
        </tbody>
    </table>








</div>
</div>


                <!--list-box end-->
            </div>

            <!--content端點01-->
        </div>
        <!--maincontent端點01-->
        <br class="clearfloat"/>
    </div>
    <!--container端點01-->
</div>









<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
